{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import datetime\n",
    "import rabbitpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Connect to the default URL of amqp://guest:guest@localhost:15672/%2F\n",
    "connection = rabbitpy.Connection()                                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    with connection.channel() as channel:\n",
    "        properties = {'content_type': 'text/plain',\n",
    "                      'timestamp': datetime.datetime.now(), \n",
    "                      'message_type': 'graphite metric'}\n",
    "        body = 'server.cpu.utilization 25.5 1350884514'\n",
    "        message = rabbitpy.Message(channel, body, properties)\n",
    "        message.publish('chapter2-example',\n",
    "                        'server-metrics',\n",
    "                        mandatory=True)\n",
    "except rabbitpy.exceptions.MessageReturnedException as error:\n",
    "    print('Publish failure: %s' % error)       "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
